<?php

function link_get_list()
{
	$sql = 'SELECT id, name, url
	        FROM Link
	        ORDER BY id';
	$data = sql_query($sql);
	return $data;
}


function link_get_by_id($id)
{
	$id = intval($id);
	$sql = 'SELECT id, name, url
	        FROM Link
	        WHERE id = '.$id.';';
	$data = sql_query($sql);
	return mysql_fetch_assoc($data);	        
}


function link_add($name, $url)
{
	$name = mysql_real_escape_string($name);
	$url = mysql_real_escape_string($url);
	$sql = 'INSERT INTO Link (name, url)
	        VALUES ("'.$name.'", "'.$url.'");';
	sql_query($sql);
}


function link_update($id, $name, $url)
{
	$id = intval($id);
	$name = mysql_real_escape_string($name);
	$url = mysql_real_escape_string($url);
	$sql = 'UPDATE Link
	        SET name = "'.$name.'",
	            url = "'.$url.'"
	        WHERE id = '.$id.';';
	sql_query($sql);
}


function link_delete($id)
{
	$id = intval($id);
	$sql = 'DELETE FROM Link
	        WHERE id = '.$id.';';
	sql_query($sql);
}


